package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.VendoutContract;
import com.lkd.contract.VendoutData;
import com.lkd.emq.Topic;
import com.lkd.entity.ChannelEntity;
import com.lkd.service.ChannelService;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;
import java.util.Optional;

@Component
@Topic(TopicConfig.VMS_VENDOUT_TOPIC)
@Slf4j
public class TaskVenOutHandler implements MsgHandler {
    @Autowired
    VendingMachineService vendingMachineService;
    @Override
    public void process(String jsonMsg) throws IOException {
        VendoutContract contract = JsonUtil.getByJson(jsonMsg, VendoutContract.class);
        //参数校验
        if (contract == null) {
            log.info("接收协议类消息为空");
        }
        //调用售货机服务进行出货
        log.info("订单对应商品信息消息接收成功");
        vendingMachineService.vendOutSku(contract);
        log.info("调用售货机出货服务");

    }
}
